<?php
/**
* 腾讯云点播
*/
namespace app\common\model;
use \think\Model;
use Vod\VodUploadClient;
use Vod\Model\VodUploadRequest;
use Vod\Exception\VodClientException;

class TencentVod 
{
    private $SecretId = 'AKID1ziAwWStgDaiaN9KNBj9KKDyszua986o';
    private $SecretKey = 'cyGPfiY9UZPyIPJznFRN3TdWzDsHPHtF';

    public function upload($filePath){
        $client = new VodUploadClient($this->SecretId, $this->SecretKey);
        $req = new VodUploadRequest();
        //$req->MediaFilePath = "/data/videos/Wildlife.wmv";
        //$req->MediaFilePath = $filePath;
        $filePath = '‪C:\Users\YM\Desktop\1.mp4';
        //var_dump(file_exists($filePath));die;
        $req->MediaFilePath = $filePath;
        try {
            $rsp = $client->upload("ap-guangzhou", $req);
            return ['FileId'=>$rsp->FileId,'MediaUrl'=>$rsp->MediaUrl];
            //echo "FileId -> ". $rsp->FileId . "\n";
            //echo "MediaUrl -> ". $rsp->MediaUrl . "\n";
        } catch (Exception $e) {
            // 处理上传异常
            //echo $e;
           return false;
        }
    }
    
    public function _sign(){
        // 确定 App 的云 API 密钥
        $secret_id = $this->SecretId;
        $secret_key = $this->SecretKey;

        // 确定签名的当前时间和失效时间
        $current = time();
        $expired = $current + 86400;  // 签名有效期：1天

        // 向参数列表填入参数
        $arg_list = array(
            "secretId" => $secret_id,
            "currentTimeStamp" => $current,
            "expireTime" => $expired,
            "random" => rand());

        // 计算签名
        $original = http_build_query($arg_list);
        $signature = base64_encode(hash_hmac('SHA1', $original, $secret_key, true).$original);

        echo $signature;
        echo "\n";
    }
    
}
